VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomct2.ocx"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmSearch 
   Caption         =   "Search "
   ClientHeight    =   8295
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   13845
   Icon            =   "frmSearch.frx":0000
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   8295
   ScaleWidth      =   13845
   WindowState     =   2  'Maximized
   Begin MSComctlLib.StatusBar StatusBar1 
      Align           =   2  'Align Bottom
      Height          =   375
      Left            =   0
      TabIndex        =   17
      Top             =   7920
      Width           =   13845
      _ExtentX        =   24421
      _ExtentY        =   661
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   1
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.ListView ListView2 
      Height          =   5895
      Left            =   0
      TabIndex        =   21
      Top             =   2040
      Visible         =   0   'False
      Width           =   13815
      _ExtentX        =   24368
      _ExtentY        =   10398
      View            =   3
      LabelEdit       =   1
      SortOrder       =   -1  'True
      Sorted          =   -1  'True
      LabelWrap       =   -1  'True
      HideSelection   =   0   'False
      FlatScrollBar   =   -1  'True
      FullRowSelect   =   -1  'True
      GridLines       =   -1  'True
      _Version        =   393217
      ColHdrIcons     =   "ImageList1"
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   11
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Text            =   "ID"
         Object.Width           =   1235
      EndProperty
      BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   1
         Text            =   "Office"
         Object.Width           =   1764
      EndProperty
      BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Alignment       =   1
         SubItemIndex    =   2
         Text            =   "Number"
         Object.Width           =   3175
      EndProperty
      BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   3
         Text            =   "Date"
         Object.Width           =   2646
      EndProperty
      BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Alignment       =   1
         SubItemIndex    =   4
         Text            =   "USD"
         Object.Width           =   1764
      EndProperty
      BeginProperty ColumnHeader(6) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Alignment       =   1
         SubItemIndex    =   5
         Text            =   "LC (VND/LAK/KHR)"
         Object.Width           =   3528
      EndProperty
      BeginProperty ColumnHeader(7) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Alignment       =   1
         SubItemIndex    =   6
         Text            =   "ROE"
         Object.Width           =   2646
      EndProperty
      BeginProperty ColumnHeader(8) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Alignment       =   1
         SubItemIndex    =   7
         Text            =   "Total"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(9) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   8
         Text            =   "Done By"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(10) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   9
         Text            =   "Receiver"
         Object.Width           =   3528
      EndProperty
      BeginProperty ColumnHeader(11) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   10
         Text            =   "Description"
         Object.Width           =   8820
      EndProperty
   End
   Begin MSComctlLib.ListView ListView1 
      Height          =   5895
      Left            =   0
      TabIndex        =   20
      Top             =   2040
      Width           =   13815
      _ExtentX        =   24368
      _ExtentY        =   10398
      SortKey         =   3
      View            =   3
      Arrange         =   1
      LabelEdit       =   1
      SortOrder       =   -1  'True
      Sorted          =   -1  'True
      LabelWrap       =   -1  'True
      HideSelection   =   0   'False
      FullRowSelect   =   -1  'True
      GridLines       =   -1  'True
      _Version        =   393217
      ColHdrIcons     =   "ImageList1"
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   15
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Text            =   "ID"
         Object.Width           =   1235
      EndProperty
      BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   1
         Text            =   "Sub ID"
         Object.Width           =   0
      EndProperty
      BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   2
         Text            =   "IDType"
         Object.Width           =   0
      EndProperty
      BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   3
         Text            =   "Number"
         Object.Width           =   3175
      EndProperty
      BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   4
         Text            =   "Office"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(6) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   5
         Text            =   "Type"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(7) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   6
         Text            =   "Company Title"
         Object.Width           =   0
      EndProperty
      BeginProperty ColumnHeader(8) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   7
         Text            =   "Date"
         Object.Width           =   1764
      EndProperty
      BeginProperty ColumnHeader(9) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   8
         Text            =   "Total in number"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(10) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   9
         Text            =   "Curr"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(11) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Alignment       =   1
         SubItemIndex    =   10
         Text            =   "Total in words"
         Object.Width           =   0
      EndProperty
      BeginProperty ColumnHeader(12) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   11
         Text            =   "Done By"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(13) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   12
         Text            =   "Receiver"
         Object.Width           =   3528
      EndProperty
      BeginProperty ColumnHeader(14) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   13
         Text            =   "Description"
         Object.Width           =   8820
      EndProperty
      BeginProperty ColumnHeader(15) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   14
         Text            =   "Bill Type"
         Object.Width           =   0
      EndProperty
   End
   Begin VB.TextBox txtGetBillType 
      Height          =   492
      Left            =   10440
      TabIndex        =   14
      Top             =   5280
      Visible         =   0   'False
      Width           =   972
   End
   Begin VB.TextBox txtToDate 
      Height          =   492
      Left            =   10440
      TabIndex        =   13
      Top             =   4320
      Visible         =   0   'False
      Width           =   852
   End
   Begin VB.TextBox txtFromDate 
      Height          =   492
      Left            =   10440
      TabIndex        =   12
      Top             =   3600
      Visible         =   0   'False
      Width           =   852
   End
   Begin VB.CommandButton cmdPreview 
      Caption         =   "Preview && Print"
      Height          =   495
      Left            =   6720
      TabIndex        =   9
      Top             =   9240
      Visible         =   0   'False
      Width           =   1815
   End
   Begin VB.Frame Frame1 
      Caption         =   "Filter option"
      Height          =   1935
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   13815
      Begin VB.CommandButton cmdClose 
         Caption         =   "Close"
         Height          =   375
         Left            =   12120
         TabIndex        =   27
         Top             =   1440
         Width           =   1335
      End
      Begin VB.OptionButton optApproved 
         Caption         =   "Approved"
         Height          =   255
         Left            =   1320
         TabIndex        =   26
         Top             =   1560
         Width           =   1575
      End
      Begin VB.OptionButton optRefusesApprove 
         Caption         =   "BM refuses to approve"
         Height          =   255
         Left            =   4800
         TabIndex        =   25
         Top             =   1560
         Visible         =   0   'False
         Width           =   1935
      End
      Begin VB.OptionButton optWaitingForApprove 
         Caption         =   "Waiting for approval"
         Height          =   255
         Left            =   2880
         TabIndex        =   24
         Top             =   1560
         Value           =   -1  'True
         Width           =   1935
      End
      Begin VB.ComboBox cboOff 
         Height          =   315
         ItemData        =   "frmSearch.frx":1CCA
         Left            =   1320
         List            =   "frmSearch.frx":1CE0
         TabIndex        =   23
         Text            =   "ALL"
         Top             =   360
         Width           =   2535
      End
      Begin VB.TextBox txtNumber 
         Height          =   405
         Left            =   10440
         TabIndex        =   18
         Top             =   720
         Width           =   3015
      End
      Begin VB.CommandButton Command1 
         Caption         =   "Search"
         Height          =   375
         Left            =   7200
         Picture         =   "frmSearch.frx":1D02
         TabIndex        =   15
         Top             =   1440
         Width           =   1335
      End
      Begin VB.ComboBox cmbBillType 
         Height          =   315
         ItemData        =   "frmSearch.frx":3EAC
         Left            =   1320
         List            =   "frmSearch.frx":3EAE
         TabIndex        =   10
         Text            =   "ALL"
         Top             =   720
         Width           =   4815
      End
      Begin VB.ComboBox cmbReceiverPayer 
         Height          =   315
         Left            =   4080
         TabIndex        =   2
         Top             =   1080
         Width           =   2055
      End
      Begin VB.ComboBox cmbDoneBy 
         Height          =   315
         Left            =   1320
         TabIndex        =   1
         Top             =   1080
         Width           =   1935
      End
      Begin MSComCtl2.DTPicker dtpFromDate 
         Height          =   375
         Left            =   7200
         TabIndex        =   3
         Top             =   240
         Width           =   1935
         _ExtentX        =   3413
         _ExtentY        =   661
         _Version        =   393216
         CustomFormat    =   "dd/MM/yyyy"
         Format          =   64880643
         CurrentDate     =   39568
      End
      Begin MSComCtl2.DTPicker dtpToDate 
         Height          =   375
         Left            =   7200
         TabIndex        =   4
         Top             =   720
         Width           =   1935
         _ExtentX        =   3413
         _ExtentY        =   661
         _Version        =   393216
         CustomFormat    =   "dd/MM/yyyy"
         Format          =   64880643
         CurrentDate     =   39568
         MinDate         =   36526
      End
      Begin VB.Label Label8 
         AutoSize        =   -1  'True
         Caption         =   "Issued by office"
         Height          =   195
         Left            =   120
         TabIndex        =   22
         Top             =   360
         Width           =   1110
      End
      Begin VB.Label Label6 
         AutoSize        =   -1  'True
         Caption         =   "Invoice number"
         Height          =   195
         Left            =   9240
         TabIndex        =   19
         Top             =   840
         Width           =   1095
      End
      Begin VB.Label Label3 
         Alignment       =   1  'Right Justify
         Caption         =   "Document"
         Height          =   255
         Left            =   360
         TabIndex        =   11
         Top             =   720
         Width           =   855
      End
      Begin VB.Label Label2 
         Caption         =   "To date"
         Height          =   375
         Left            =   6480
         TabIndex        =   8
         Top             =   600
         Width           =   615
      End
      Begin VB.Label Label1 
         Caption         =   "From date"
         Height          =   375
         Left            =   6360
         TabIndex        =   7
         Top             =   240
         Width           =   855
      End
      Begin VB.Label Label4 
         Alignment       =   1  'Right Justify
         Caption         =   "Done by"
         Height          =   255
         Left            =   360
         TabIndex        =   6
         Top             =   1080
         Width           =   855
      End
      Begin VB.Label Label5 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "Receiver "
         Height          =   195
         Left            =   3360
         TabIndex        =   5
         Top             =   1080
         Width           =   690
      End
   End
   Begin MSComctlLib.ImageList ImageList1 
      Left            =   11880
      Top             =   720
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   17
      ImageHeight     =   17
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   3
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmSearch.frx":3EB0
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmSearch.frx":608D
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmSearch.frx":77F0
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin VB.Label lblTitle 
      AutoSize        =   -1  'True
      Caption         =   "INVOICE"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   18
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H8000000D&
      Height          =   435
      Left            =   360
      TabIndex        =   16
      Top             =   2880
      Width           =   1575
   End
End
Attribute VB_Name = "frmSearch"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmbBillType_Change()
    'Call Receiver_Data
End Sub

Private Sub cmbBillType_Click()
    If cmbBillType.Text = "Money exchange" Then
        cmbDoneBy.Enabled = False
        cmbReceiverPayer.Enabled = False
        ListView1.Visible = False
        ListView2.Visible = True
    Else
        cmbDoneBy.Enabled = True
        cmbReceiverPayer.Enabled = True
        ListView1.Visible = True
        ListView2.Visible = False
    End If
    Command1_Click
End Sub

Private Sub cmbDoneBy_Change()
    'Call Receiver_Data
End Sub

Private Sub cmbReceiverPayer_Change()
    'Call Receiver_Data
End Sub

Private Sub cmdClose_Click()
    'If MsgBox("Are you sure???", vbOKCancel + vbQuestion, "Note...") = vbOK Then
        Unload Me
    'Else
     '   Exit Sub
   ' End If
End Sub

Private Sub cmdEdit_Click()
    If (ListView1.ListItems.Count <= 0) Then Exit Sub
    ' Load frmIncoice
    ' Call frmIncoice.filledindata(Grid1.TextMatrix(Grid1.Row, 0))
    ' frmIncoice.SetCommandStatusForDetail ("DELEDITADDPREVIEW")
    
    ' frmIncoice.Show
    
    'Call SetParent(frmIncoice.hWnd, frmMain.Picture1.hWnd)
    ' frmMain.Picture1.ZOrder (0)
    ' frmIncoice.BorderStyle = 0
    Load frmIncoice
    'Call frmIncoice.Move(0, 0)
    'frmIncoice.ZOrder (0)
    'frmIncoice.BorderStyle = 0
    'frmIncoice.lblTitle = "RECEIPT"
    'frmIncoice.txtBillType.Text = "RC"
    'frmIncoice.Label1(0).Caption = "Offc"
    'Call frmIncoice.CreatIDNumber
    'ListView1.SelectedItem.SubItems(3)
    frmIncoice.SetCommandStatusForDetail ("DELEDITADDPREVIEW")
    
    Call SetOffcValue(frmIncoice.cmbOFFC, GetBillType(ListView1.SelectedItem.SubItems(3)))
    Call SetTypeValue(frmIncoice.cboType, GetBillType(ListView1.SelectedItem.SubItems(3)))
    frmIncoice.filledindata (ListView1.SelectedItem.SubItems(3))
    
    frmIncoice.Show
    frmIncoice.cmbOFFC.Text = ""
    If UCase(Trim(GetBillType(ListView1.SelectedItem.SubItems(3)))) = "RC" Then
        frmIncoice.Label1(0).Caption = "Source"
        frmIncoice.cboFinancial.Visible = True
        frmIncoice.lblFinancial.Visible = True
    End If
End Sub

Private Function GetBillType(inumber As String) As String
    Dim sql As String
    Dim rs As New ADODB.Recordset
    sql = "Select billtype from detail where inumber ='" & inumber & "'"
    Set rs = adoConnection.Execute(sql)
    GetBillType = ""
    If Not rs.EOF Then
        If Not IsNull(rs.Fields("billtype").Value) Then
            GetBillType = rs.Fields("billtype").Value
        End If
    End If
    rs.Close
    Set rs = Nothing
End Function

Private Sub Command1_Click()
    StatusBar1.Panels(1).Text = "Searching..."
    Receiver_Data
    Format
    StatusBar1.Panels(1).Text = "Done"
     
    ListView1.Enabled = True
    ListView2.Enabled = True
End Sub

 

Private Sub dtpFromDate_Change()
    Call FromDate
    txtFromDate.Text = ""
        txtFromDate.Text = txtFromDate.Text & dtpFromDate.Year
        If dtpFromDate.Year > 2000 Then
            txtFromDate.Text = Val(txtFromDate.Text) - 2000
            If txtFromDate.Text < 10 Then
                txtFromDate.Text = "0" & txtFromDate.Text
            End If
        End If
        If dtpFromDate.Month < 10 Then
            txtFromDate.Text = txtFromDate.Text & "0" & dtpFromDate.Month
        Else
                txtFromDate.Text = txtFromDate.Text & dtpFromDate.Month
        End If
        If dtpFromDate.Day < 10 Then
                    txtFromDate.Text = txtFromDate & "0" & dtpFromDate.Day
        Else
                    txtFromDate.Text = txtFromDate.Text & dtpFromDate.Day
        End If
        
        
        txtToDate.Text = ""
        txtToDate.Text = txtToDate.Text & dtpToDate.Year
        If dtpToDate.Year > 2000 Then
            txtToDate.Text = Val(txtToDate.Text) - 2000
            If txtToDate.Text < 10 Then
                txtToDate.Text = "0" & txtToDate.Text
            End If
        End If
        If dtpToDate.Month < 10 Then
            txtToDate.Text = txtToDate.Text & "0" & dtpToDate.Month
        Else
                txtToDate.Text = txtToDate.Text & dtpToDate.Month
        End If
        If dtpToDate.Day < 10 Then
                    txtToDate.Text = txtToDate & "0" & dtpToDate.Day
        Else
                    txtToDate.Text = txtToDate.Text & dtpToDate.Day
        End If
    'Call Receiver_Data
End Sub

Private Sub dtpToDate_Change()
    Call ToDate
    'Call Receiver_Data
End Sub

Private Sub Form_Load()
    'Grid1.Rows = 1
    ' Grid1.Cols = 10
    Call setGridHeader
    'dtpFromDate.Value = Date
    
    dtpFromDate.Day = 1
    dtpFromDate.Month = Month(Date)
    dtpFromDate.Year = Year(Date)
    dtpToDate.Value = Date
    
    Call KetNoi
    
    If (permit <> "A" And permit <> "G") Then
        cboOff.Enabled = False
    ElseIf permit = "A" Or permit = "G" Then
        cboOff.Enabled = True
    
    End If
    If stroffice = "IND" Then
        cboOff.Enabled = True
    End If
    Call List
    Call FromDate
    Call ToDate
    
    Format
    Me.Height = Screen.Height - 1900
    Me.Width = Screen.Width - 350
    Me.Top = 0 ' Screen.Height / 2 - (Me.Height / 1.8)
    Me.Left = 0 ' Screen.Width / 2 - (Me.Width / 2)
    If Me.Top + Me.Height > Screen.Height Then
        Me.Height = Screen.Height
    End If
    'If permit = "B" Or permit = "G" Then
    '   optWaitingForApprove.Value = True
    
    'End If
    Command1_Click
End Sub
Public Sub Format()
'     With Grid1
'        .FormatString = "Sub ID|IDType | Done By|Receiver|Company Title|Date|Description|Total in Number|Total in words|Number|Bill Type"
'    End With

    'ListView1.ColumnHeaders.item(0).Width = 0
'    ListView1.ColumnHeaders.item(1).Width = 1000
'    ListView1.ColumnHeaders.item(2).Width = 0
'    ListView1.ColumnHeaders.item(3).Width = 0
'    ListView1.ColumnHeaders.item(4).Width = 1500
'    ListView1.ColumnHeaders.item(5).Width = 1500
'    ListView1.ColumnHeaders.item(6).Width = 2000
'    ListView1.ColumnHeaders.item(7).Width = 0
'    ListView1.ColumnHeaders.item(8).Width = 1000
'    ListView1.ColumnHeaders.item(9).Width = 0
'    ListView1.ColumnHeaders.item(10).Width = 2000
'
''    Grid1.ColWidth(0) = 0
'    Grid1.ColWidth(1) = 0
'    Grid1.ColWidth(2) = 1500
'    Grid1.ColWidth(3) = 1500
'    Grid1.ColWidth(4) = 1500
'    Grid1.ColWidth(5) = 1000
'    Grid1.ColWidth(6) = 2000
'    Grid1.ColWidth(7) = 1000
'    Grid1.ColWidth(8) = 2000
'    Grid1.ColWidth(9) = 2000
'    Grid1.ColWidth(10) = 0
End Sub

Private Sub setGridHeader()
'    With Grid1
'        .FormatString = .FormatString = "Sub ID|IDType | Done By|Receiver|Company Title|Date|Description|Total in Number|Total in words|Number|Bill Type"
'    End With
    'ListView1.ColumnHeaders.item(0).Width = 0
'    ListView1.ColumnHeaders.item(1).Width = 1000
'    ListView1.ColumnHeaders.item(2).Width = 0
'    ListView1.ColumnHeaders.item(3).Width = 0
'    ListView1.ColumnHeaders.item(4).Width = 1500
'    ListView1.ColumnHeaders.item(5).Width = 1500
'    ListView1.ColumnHeaders.item(6).Width = 200
'    ListView1.ColumnHeaders.item(7).Width = 0
'    ListView1.ColumnHeaders.item(8).Width = 1000
'    ListView1.ColumnHeaders.item(9).Width = 100
'    ListView1.ColumnHeaders.item(10).Width = 2000
    
'    Grid1.ColWidth(0) = 0
'    Grid1.ColWidth(1) = 0
'    Grid1.ColWidth(2) = 1500
'    Grid1.ColWidth(3) = 1500
'    Grid1.ColWidth(4) = 1500
'    Grid1.ColWidth(5) = 1000
'    Grid1.ColWidth(6) = 2000
'    Grid1.ColWidth(7) = 1000
'    Grid1.ColWidth(8) = 2000
'    Grid1.ColWidth(9) = 2000
    'Grid1.ColWidth(10) = 0
         
End Sub
Private Sub List()
    Dim I As Integer
    Dim strr As String
    
    
    I = 1
    strr = "SELECT distinct doneby from detail"
    Set gRs = New ADODB.Recordset
    gRs.Open strr, adoConnection, adOpenDynamic, adLockOptimistic
    cmbDoneBy.Clear
    cmbDoneBy.AddItem "ALL"
    With gRs
        If (Not (.BOF And .EOF)) Then
            Do Until gRs.EOF
                'cmbBillType.AddItem (Trim(.Fields(9).Value))
                cmbDoneBy.AddItem (Trim(.Fields(0).Value))
               ' cmbReceiverPayer.AddItem (Trim(.Fields(2).Value))
            I = I + 1
        .MoveNext
        Loop
        .MoveFirst
        End If
    End With
    cmbDoneBy.ListIndex = 0
    gRs.Close
    
    strr = "SELECT distinct receiverpayer from detail"
    Set gRs = New ADODB.Recordset
    gRs.Open strr, adoConnection, adOpenDynamic, adLockOptimistic
    cmbReceiverPayer.Clear
    cmbReceiverPayer.AddItem "ALL"
    With gRs
        If (Not (.BOF And .EOF)) Then
            Do Until gRs.EOF
                'cmbBillType.AddItem (Trim(.Fields(9).Value))
                'cmbDoneBy.AddItem (Trim(.Fields(1).Value))
               cmbReceiverPayer.AddItem (Trim(.Fields(0).Value))
            I = I + 1
        .MoveNext
        Loop
        .MoveFirst
        End If
    End With
    cmbReceiverPayer.ListIndex = 0
    gRs.Close
    
    
    strr = "SELECT distinct BillType from detail"
    Set gRs = New ADODB.Recordset
    gRs.Open strr, adoConnection, adOpenDynamic, adLockOptimistic
    cmbBillType.Clear
    cmbBillType.AddItem "ALL (Not included Money exchange & Bank Cash Tranfer)"
    With gRs
        If (Not (.BOF And .EOF)) Then
            Do Until gRs.EOF
                'cmbBillType.AddItem (Trim(.Fields(9).Value))
                'cmbDoneBy.AddItem (Trim(.Fields(1).Value))
               cmbBillType.AddItem GetBillTypeDescription(Trim(.Fields(0).Value))
            I = I + 1
        .MoveNext
        Loop
        .MoveFirst
        End If
    End With
    cmbBillType.ListIndex = 0
 
    Set gRs = Nothing
    cmbBillType.AddItem "Money exchange"
    cmbBillType.AddItem "Cash and Bank Transfer"
End Sub

Private Function FromDate() As String
    txtFromDate.Text = ""
    If Val(dtpFromDate.Year) > 2000 Then
        txtFromDate.Text = (dtpFromDate.Year) - 2000
    End If
    If txtFromDate.Text < 10 Then
        txtFromDate.Text = "0" & txtFromDate.Text
    End If
    If dtpFromDate.Month < 10 Then
        txtFromDate.Text = txtFromDate.Text & "0" & dtpFromDate.Month
    Else
        txtFromDate.Text = txtFromDate.Text & dtpFromDate.Month
    End If
    If dtpFromDate.Day < 10 Then
        txtFromDate.Text = txtFromDate & "0" & dtpFromDate.Day
    Else
        txtFromDate.Text = txtFromDate & dtpFromDate.Day
    End If
    FromDate = txtFromDate.Text
End Function
Private Function ToDate() As String
txtToDate.Text = ""
    If Val(dtpToDate.Year) > 2000 Then
        txtToDate.Text = (dtpToDate.Year) - 2000
    End If
    If txtToDate.Text < 10 Then
        txtToDate.Text = "0" & txtToDate.Text
    End If
    If dtpToDate.Month < 10 Then
        txtToDate.Text = txtToDate.Text & "0" & dtpToDate.Month
    Else
        txtToDate.Text = txtToDate.Text & dtpToDate.Month
    End If
    If dtpToDate.Day < 10 Then
        txtToDate.Text = txtToDate & "0" & dtpToDate.Day
    Else
        txtToDate.Text = txtToDate & dtpToDate.Day
    End If
ToDate = txtToDate.Text
End Function

Public Sub Receiver_Data(Optional ByVal strSortCretarial As String)
    Dim strr As String
    Dim I, N As Integer
    Dim J As Long
    Dim condition As String
    Dim ApproveCondition As String
    Dim OrderBy As String
    
    If strSortCretarial <> "" Then
        OrderBy = strSortCretarial
        ListView1.Sorted = False
    Else
        OrderBy = " order by inumber desc"
    End If
    StatusBar1.Panels(1).Text = "Searching..."
 


    '"order by mnumber desc"
    If optWaitingForApprove.Value Then
        ApproveCondition = " Approved = '0' "
    ElseIf optApproved.Value Then
        ApproveCondition = " (  Approved is null  or Approved = '' or Approved = '1') "
    ElseIf optRefusesApprove.Value Then
        ApproveCondition = " (  Approved = '2') "
    Else
        MsgBox "Search result: unknown document status???", vbCritical + vbOKOnly, "Searching"
        Exit Sub
    End If
    
    If Left(cmbBillType.Text, 3) <> "ALL" Then
        txtGetBillType.Text = GetBill(cmbBillType.Text)
    Else
        txtGetBillType.Text = "ALL"
    End If
    condition = ""
    If UCase(cmbDoneBy.Text) <> "ALL" Then
        condition = " and doneby ='" & cmbDoneBy.Text & "' "
    End If
    
    If UCase(cmbReceiverPayer.Text) <> "ALL" Then
        If condition <> "" Then
            condition = condition & " and ReceiverPayer ='" & cmbReceiverPayer.Text & "' "
        Else
            condition = "  and ReceiverPayer ='" & cmbReceiverPayer.Text & "' "
        End If
    End If
    
    If UCase(txtGetBillType.Text) <> "ALL" Then
        If condition <> "" Then
            condition = condition & " and BillType ='" & txtGetBillType.Text & "' "
        Else
            condition = "  and BillType ='" & txtGetBillType.Text & "' "
        End If
    End If
    condition = condition & " and " & ApproveCondition
    'strr = "SELECT * from detail WHERE BillType = '" & txtGetBillType.Text & "' and doneby = '" & cmbDoneBy.Text & "' and receiverpayer = '" & cmbReceiverPayer.Text & "'"
    If cboOff.Enabled = True Then
        If Trim(txtNumber.Text) <> "" Then
            If cboOff.Text = "ALL" Then
                strr = "select * from detail where office like '%' and  inumber like '%" & UCase(txtNumber.Text) & "%' " & OrderBy
            Else
            
                strr = "select * from detail where office like '" & cboOff.Text & "' and  inumber like '%" & UCase(txtNumber.Text) & "%' " & OrderBy
            End If
        Else
            If cboOff.Text = "ALL" Then
                strr = "SELECT * from detail where office like '%' and  val(cdate) >=" & Val(txtFromDate.Text) & " and val(cdate) <= " & Val(txtToDate.Text) & condition & " " & OrderBy
            Else
            
                strr = "SELECT * from detail where office like '" & cboOff.Text & "' and  val(cdate) >=" & Val(txtFromDate.Text) & " and val(cdate) <= " & Val(txtToDate.Text) & condition & " " & OrderBy
            End If
        End If
    Else
        If Trim(txtNumber.Text) <> "" Then
            strr = "select * from detail where office like '" & stroffice & "' and  inumber like '%" & UCase(txtNumber.Text) & "%' " & OrderBy
        Else
            strr = "SELECT * from detail where office like '" & stroffice & "' and  val(cdate) >=" & Val(txtFromDate.Text) & " and val(cdate) <= " & Val(txtToDate.Text) & condition & " " & OrderBy
        End If
    End If
    Set gRs = New ADODB.Recordset
    If txtGetBillType.Text = "ME" Then
             
        If strSortCretarial <> "" Then
            OrderBy = strSortCretarial
            ListView2.Sorted = False
        Else
            OrderBy = "order by mnumber desc"
        End If
        
    '"order by mnumber desc"
        If cboOff.Enabled = True Then
            If Trim(txtNumber.Text) <> "" Then
                If cboOff.Text = "ALL" Then
                    strr = "select * from MoneyExchange where office like '%' and  mnumber like '%" & UCase(txtNumber.Text) & "%' " & OrderBy
                Else
                    strr = "select * from MoneyExchange where office like '" & cboOff.Text & "' and  mnumber like '%" & UCase(txtNumber.Text) & "%' " & OrderBy
                End If
            Else
                If cboOff.Text = "ALL" Then
                    strr = "Select * from MoneyExchange where office like '%' and  val(mdate) >=" & Val(txtFromDate.Text) & " and val(mdate) <= " & Val(txtToDate.Text) & " and " & ApproveCondition & " " & OrderBy
                Else
                    strr = "Select * from MoneyExchange where office like '" & cboOff.Text & "' and  val(mdate) >=" & Val(txtFromDate.Text) & " and val(mdate) <= " & Val(txtToDate.Text) & " and " & ApproveCondition & " " & OrderBy
                End If
            End If
        Else
            If Trim(txtNumber.Text) <> "" Then
                strr = "select * from MoneyExchange where office ='" & stroffice & "' and  mnumber like '%" & UCase(txtNumber.Text) & "%' " & OrderBy
            Else
                strr = "Select * from MoneyExchange where office ='" & stroffice & "' and  val(mdate) >=" & Val(txtFromDate.Text) & " and val(mdate) <= " & Val(txtToDate.Text) & " and " & ApproveCondition & " " & OrderBy
            End If
        End If
    End If
    gRs.Open strr, adoConnection, adOpenDynamic, adLockOptimistic
    I = 1
    ListView1.ListItems.Clear
    ListView2.ListItems.Clear
    Do While gRs.EOF = False
    
        
        With gRs
            If txtGetBillType.Text = "ME" Then
                Set item = ListView2.ListItems.Add(, , I)
                item.SubItems(1) = Trim(GetFieldValue(.Fields("moffc")))
                item.SubItems(2) = Trim(GetFieldValue(.Fields("mnumber")))
                item.SubItems(3) = Right(Trim(GetFieldValue(.Fields("mdate"))), 2) & "/" & Left(MonthName(Mid(Trim(GetFieldValue(.Fields("mdate"))), 3, 2)), 3) & "/" & Left(Trim(GetFieldValue(.Fields("mdate"))), 2)
                If Trim(GetFieldValue(.Fields("musd"))) <> "" Then
                    item.SubItems(4) = FormatNumber(Trim(GetFieldValue(.Fields("musd"))), 0, vbUseDefault, vbUseDefault, vbUseDefault)
                Else
                    item.SubItems(4) = ""
                End If
                
                If Trim(GetFieldValue(.Fields("mvnd"))) <> "" Then
                    item.SubItems(5) = FormatNumber(Trim(GetFieldValue(.Fields("mvnd"))), 0, vbUseDefault, vbUseDefault, vbUseDefault)
                Else
                    item.SubItems(5) = ""
                End If
                item.SubItems(6) = Trim(GetFieldValue(.Fields("ROE")))
                
                
'                    If Right(Trim(GetFieldValue(.Fields("twords"))), Len("Dollars")) = "Dollars" Then
'                        item.SubItems(7) = "USD"
'                    Else
'                        item.SubItems(7) = "LC"
'                    End If
                
                If Trim(GetFieldValue(.Fields("tnumber"))) <> "" Then
                    item.SubItems(7) = FormatNumber(Trim(GetFieldValue(.Fields("tnumber"))), 0, vbUseDefault, vbUseDefault, vbUseDefault)
                Else
                    item.SubItems(7) = ""
                End If
                item.SubItems(8) = Trim(GetFieldValue(.Fields("doneby")))
                item.SubItems(9) = Trim(GetFieldValue(.Fields("receiverpayer")))
                item.SubItems(10) = Trim(GetFieldValue(.Fields("des")))
                ListView2.Visible = True
                ListView1.Visible = False
            Else
                Set item = ListView1.ListItems.Add(, , I)
                item.SubItems(1) = Trim(GetFieldValue(.Fields(0)))
                item.SubItems(2) = Trim(GetFieldValue(.Fields(1)))
                item.SubItems(3) = Trim(GetFieldValue(.Fields(11)))
                item.SubItems(4) = getOfficeForSearchForm(GetFieldValue(.Fields(0)), GetFieldValue(.Fields(12)))
                item.SubItems(5) = getTypeForSearchForm(GetFieldValue(.Fields(0)), GetFieldValue(.Fields(12)))
                
                item.SubItems(7) = Right(Trim(GetFieldValue(.Fields(5))), 2) & "/" & Left(MonthName(Mid(Trim(GetFieldValue(.Fields(5))), 3, 2)), 3) & "/" & Left(Trim(GetFieldValue(.Fields(5))), 2)
                If Trim(GetFieldValue(.Fields(7))) <> "" Then
                    item.SubItems(8) = FormatNumber(Trim(GetFieldValue(.Fields(7))), 0, vbUseDefault, vbUseDefault, vbUseDefault)
                Else
                    item.SubItems(8) = ""
                End If
                If InStr(1, Trim(GetFieldValue(.Fields("twords"))), "LC", vbTextCompare) Then
                    item.SubItems(9) = "LC"
                Else
                    item.SubItems(9) = "USD"
                End If
                
                item.SubItems(10) = Trim(GetFieldValue(.Fields(8)))
                
                item.SubItems(11) = Trim(GetFieldValue(.Fields(2)))  'done by
                item.SubItems(12) = Trim(GetFieldValue(.Fields(3)))
                item.SubItems(13) = Trim(GetFieldValue(.Fields(6)))  'des
                item.SubItems(14) = Trim(GetFieldValue(.Fields(10)))
                 ListView2.Visible = False
                ListView1.Visible = True
            End If
        End With
        gRs.MoveNext
        I = I + 1
        N = I
        Loop
        gRs.Close
        Set gRs = Nothing
        If strSortCretarial = "" Then
            For I = 1 To 11
                ListView2.ColumnHeaders(I).Icon = 3
            Next I
            
            For I = 1 To 15
                ListView1.ColumnHeaders(I).Icon = 3
            Next I
            
            ListView1.ColumnHeaders(4).Icon = 1
            ListView2.ColumnHeaders(3).Icon = 1
        End If
    StatusBar1.Panels(1).Text = "Done"
    'Bat dau kiem tra du lieu theo ngay thang
   
End Sub

Private Sub Form_Resize()
    ListView1.Width = Me.Width - 200
    ListView2.Width = Me.Width - 200
    ListView1.Height = Me.Height - ListView1.Top - StatusBar1.Height - 600
    ListView2.Height = Me.Height - ListView2.Top - StatusBar1.Height - 600
End Sub

Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    With ListView1
        If ColumnHeader.Index - 1 = 0 Then
            Exit Sub
        End If
        ListView1.SortKey = ColumnHeader.Index - 1
        If ListView1.SortOrder = lvwAscending Then
            If ColumnHeader.Index - 1 = 8 Then
                ListView1.SortOrder = lvwDescending
                Receiver_Data (" order by tnumber desc")
            ElseIf ColumnHeader.Index - 1 = 7 Then
                ListView1.SortOrder = lvwDescending
                Receiver_Data (" order by cdate desc")
            Else
                ListView1.SortOrder = lvwDescending
            End If
            For I = 1 To 15
                .ColumnHeaders(I).Icon = 3
            Next I
            
            ColumnHeader.Icon = 1
         Else
             If ColumnHeader.Index - 1 = 8 Then
                 ListView1.SortOrder = lvwAscending
                 Receiver_Data (" order by tnumber asc")
             ElseIf ColumnHeader.Index - 1 = 7 Then
                 ListView1.SortOrder = lvwAscending
                 Receiver_Data (" order by cdate asc")
             Else
                 ListView1.SortOrder = lvwAscending
             End If
             
             For I = 1 To 15
                 .ColumnHeaders(I).Icon = 3
             Next I
            
             ColumnHeader.Icon = 2
         End If
         If ColumnHeader.Index - 1 = 8 Or ColumnHeader.Index - 1 = 7 Then
         Else
             ListView1.Sorted = True
         End If
    End With
End Sub

Private Sub ListView1_ItemClick(ByVal item As MSComctlLib.ListItem)

'MsgBox GetTypeDescription(Left(Item.SubItems(5), 5))
End Sub

Private Sub ListView1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
    Dim temp As String
    temp = getDes(ListView1.HitTest(x, Y))
    
    If Trim(temp) <> "" Then
        If Len(temp) >= 5 Then
            temp = Left(temp, 5)
            ListView1.ToolTipText = GetTypeDescription(temp)
        End If
    End If
End Sub

Private Function getDes(lvv As ListItem) As String
    On Error GoTo L
    getDes = lvv.SubItems(5)
    Exit Function
L:
    getDes = ""
    Exit Function
End Function
Private Sub ListView2_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

    'With ListView2
    '   ListView1.SortKey = ColumnHeader.Index - 1
    '    If ListView1.SortOrder = lvwAscending Then
    '        ListView1.SortOrder = lvwDescending
    '        For i = 1 To 11
    '            .ColumnHeaders(i).Icon = 3
    '        Next i
    '
    '        ColumnHeader.Icon = 1
    '    Else
    '        ListView1.SortOrder = lvwAscending
    '        For i = 1 To 11
    '            .ColumnHeaders(i).Icon = 3
    '        Next i
    '
    '        ColumnHeader.Icon = 2
    '    End If
    '    ListView1.Sorted = True
    '
    '
    'End With
    With ListView2
        If (ColumnHeader.Index - 1 = 0) Or (ColumnHeader.Index >= 5 And ColumnHeader.Index <= 8) Then
            Exit Sub
        End If
        ListView2.SortKey = ColumnHeader.Index - 1
        If ListView2.SortOrder = lvwAscending Then
            If ColumnHeader.Index = 4 Then
                ListView2.SortOrder = lvwDescending
                Receiver_Data (" order by mdate desc")
            ElseIf ColumnHeader.Index = 5 Then
                ListView2.SortOrder = lvwDescending
                Receiver_Data (" order by musd desc")
            ElseIf ColumnHeader.Index = 6 Then
                ListView2.SortOrder = lvwDescending
                Receiver_Data (" order by mvnd desc")
            ElseIf ColumnHeader.Index = 7 Then
                ListView2.SortOrder = lvwDescending
                Receiver_Data (" order by ROE desc")
            ElseIf ColumnHeader.Index = 8 Then
                ListView2.SortOrder = lvwDescending
                Receiver_Data (" order by tnumber desc")
            Else
                ListView2.SortOrder = lvwDescending
            End If
            For I = 1 To 11
                .ColumnHeaders(I).Icon = 3
            Next I
            
            ColumnHeader.Icon = 1
        Else
            If ColumnHeader.Index = 4 Then
                ListView2.SortOrder = lvwAscending
                Receiver_Data (" order by mdate asc")
            ElseIf ColumnHeader.Index = 5 Then
                ListView2.SortOrder = lvwAscending
                Receiver_Data (" order by musd asc")
            ElseIf ColumnHeader.Index = 6 Then
                ListView2.SortOrder = lvwAscending
                Receiver_Data (" order by mvnd asc")
            ElseIf ColumnHeader.Index = 7 Then
                ListView2.SortOrder = lvwAscending
                Receiver_Data (" order by ROE asc")
            ElseIf ColumnHeader.Index = 8 Then
                ListView2.SortOrder = lvwAscending
                Receiver_Data (" order by tnumber asc")
            Else
                ListView2.SortOrder = lvwAscending
            End If
            
            For I = 1 To 11
                .ColumnHeaders(I).Icon = 3
            Next I
            
            ColumnHeader.Icon = 2
        End If
        If ColumnHeader.Index >= 4 And ColumnHeader.Index <= 8 Then
        Else
            ListView2.Sorted = True
        End If
    End With
End Sub
Private Function GetBill(billcode As String) As String
    Select Case billcode
        Case "Invoice"
            GetBill = "IV"
        Case "Budget flow"
            GetBill = "BF"
        Case "Receipt"
            GetBill = "RC"
        Case "Temporary invoice"
            GetBill = "TI"
        Case "Temporary receipt"
            GetBill = "TR"
        Case "Money exchange", "Cash and Bank Transfer"
            GetBill = "ME"
        Case Else
            GetBill = "Unkow Bill description"
    End Select
End Function


Private Sub Grid1_DblClick()
    Call cmdEdit_Click
End Sub

Private Sub ListView1_DblClick()
    cmdEdit_Click
End Sub

Private Sub ListView2_DblClick()
    If ListView2.ListItems.Count <= 0 Then Exit Sub
    If getMoneyTypeFromMoneyTransfer(ListView2.SelectedItem.SubItems(2)) <> "" Then
        
        Load frmCBT
        
        frmCBT.SetCommandStatusForDetail ("DELEDITADDPREVIEW")
        frmCBT.Show
        frmCBT.filledindata (ListView2.SelectedItem.SubItems(2))
    Else
    
        Load frmME
        
        frmME.SetCommandStatusForDetail ("DELEDITADDPREVIEW")
        frmME.Show
        frmME.filledindata (ListView2.SelectedItem.SubItems(2))
    End If
End Sub

Private Sub optApproved_Click()
    StatusBar1.Panels(1).Text = "Click search button please!"
    ListView1.Enabled = False
    ListView2.Enabled = False
    Command1_Click
End Sub

Private Sub optRefusesApprove_Click()
    StatusBar1.Panels(1).Text = "Click search button please!"
    ListView1.Enabled = False
    ListView2.Enabled = False
End Sub

Private Sub optWaitingForApprove_Click()
    StatusBar1.Panels(1).Text = "Click search button please!"
    ListView1.Enabled = False
    ListView2.Enabled = False
    Command1_Click
End Sub

Private Sub txtNumber_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        Command1_Click
    End If
End Sub
